<template>
    <div>
        <!--查询条件start --111s-->
        <el-card>

        <el-form :inline="true" :model="query" class="query-form" size="small">
            <el-form-item><span>商品名称：</span>
            <el-form-item  class="query-form-item">
                <el-input
                    v-model="query.content"
                    placeholder="请输入商品名"
                    prefix-icon="el-icon-search"
                    @keyup.enter.native="onSubmit"
                    clearable
                ></el-input>
            </el-form-item></el-form-item>
            <el-form-item >
                <span>商品分类：</span>

                <el-select  v-model="query.thirdcategoryid"  placeholder="请选择"  @change="thirdchange1(1)"  clearable >
                    <el-option v-for="item in busCommodityThirdCategoryList" :key="item.topcategoryid"
                               :label="item.topcategoryname"
                               :value="item.topcategoryid"
                    >
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-button
                    type="primary"
                    icon="el-icon-refresh"
                    @click="onRest" size="small"
                ></el-button>
                <el-button type="primary" icon="el-icon-search" @click="onSubmit" size="small"
                >查询</el-button
                >
                <!-- <el-button
                  v-if="!isSkip"
                  type="primary"
                  icon="el-icon-edit"
                  @click.native="handleForm()"
                  >添加</el-button
                > -->
            </el-form-item>
        </el-form>
        <!--列表start --222s-->
        <el-table
            ref="multipleTable"
            v-loading="loading"
            :data="list"
            :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
            @selection-change="handleSelectionChange"
            border
        >
            <el-table-column type="selection" width="50" fixed />
            <el-table-column
                label="商品ID"
                prop="commodityid"
                width="50"
                align="center"
            />

            <el-table-column
                label="商品图片"
                prop="commodityicon"
                align="center"
                width="150"
            >
                <template slot-scope="scope">
                    <el-popover
                        v-if="scope.row.commodityicon"
                        placement="right"
                        trigger="hover"
                    >
                        <img
                            :src="scope.row.commodityicon"
                            style="width: 400px; border-radius: 3px"
                        />
                        <img
                            slot="reference"
                            :src="scope.row.commodityicon"
                            style="max-height: 80px; max-width: 50px; border-radius: 5px"
                        />
                    </el-popover>
                    <span v-else>-</span>
                </template>
            </el-table-column>
            <el-table-column
                label="商品名称"
                prop="commodityname"
                width="150"
                align="center"
            />
            <el-table-column
                label="一级分类"
                prop="topcategoryname"
                width="150"
                align="center"
            />
            <el-table-column
                label="二级分类"
                prop="secondarycategoryname"
                width="150"
                align="center"
            />
            <el-table-column
                label="三级分类"
                prop="thirdcategoryname"
                width="150"
                align="center"
            />
            <el-table-column label="审核状态" with="100" align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.commoditystatus == 0">审核中</span>
                    <span v-if="scope.row.commoditystatus == 1">审核通过</span>
                    <span v-if="scope.row.commoditystatus == 2">审核拒绝</span>
                </template>
            </el-table-column>
            <el-table-column
                label="库存"
                prop="commoditynum"
                width="150"
                align="center"
            />

            <el-table-column
                label="添加时间"
                with="300"
                :show-overflow-tooltip="true"
                align="center"
            >
                <template slot-scope="scope">
                    <i class="el-icon-time" v-if="scope.row.createtime != null"></i>
                    <span v-if="scope.row.createtime != null">{{
            scope.row.createtime | formatDateStr("yyyy-MM-dd hh:mm:ss")
          }}</span>
                </template>
            </el-table-column>

            <el-table-column label="操作" align="center" fixed="right" width="160">
                <template slot-scope="scope">
                    <el-button
                        type="primary"
                        size="mini"
                        @click.native="detailForm(scope.$index, scope.row)"
                        
                    >查看
                    </el-button>
                    <el-button
                        type="primary"
                        size="mini"
                        @click.native="editForm(scope.$index, scope.row)"
                    >编辑
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--分页模块start-->
        <el-pagination
            class="pagination-container"
            background
            :page-size="query.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total,sizes,prev, pager, next, jumper"
            :current-page="query.currentPage"
            :page-sizes="[5,10, 20, 30, 50]"
            :total="totalNumber"
        ></el-pagination>
        <!--分页模块end-->

        <!--查看弹框-->
        <el-dialog
            title="查看"
            :visible.sync="detailVisible"
            :before-close="hideDetailForm"
            width="50%"
            top="5vh"
            v-dialogDrag
            :close-on-click-modal="false"
        >
        <template slot="title">
            <div class="avue-crud__dialog__header">
                <span class="el-dialog__title">
                <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                查看
                </span>
            </div>
        </template>
        <el-card>

            <el-form :model="formData" label-width="140px">
                <el-form-item label="商品名称:">
                    <input v-model="formData.commodityname" type="text" readonly />
                </el-form-item>
                <el-form-item label="商品分类:">
          <span>{{
            formData.topcategoryname +
            "," +
            formData.secondarycategoryname +
            "," +
            formData.thirdcategoryname
          }}</span>
                </el-form-item>

                <el-form-item
                    style="border-bottom: 1px solid #ebeef5"
                    label-width="0px"
                >
                    <el-form-item
                        label="代理价:"
                        style="width: 30%; display: inline-block"
                    >
                        <input v-model="formData.commodityoldprice" type="text" readonly />
                    </el-form-item>
                    <el-form-item
                        label="售价:"
                        style="margin-left: 80px; width: 30%; display: inline-block"
                    >
                        <input v-model="formData.commodityprice" type="text" readonly />
                    </el-form-item>
                </el-form-item>

                <el-form-item
                    style="border-bottom: 1px solid #ebeef5"
                    label-width="0px"
                >
                    <el-form-item
                        label="添加时间:"
                        style="width: 30%; display: inline-block"
                    >
                        <input
                            :value="formData.createtime | formatDateStr('yyyy-MM-dd')"
                            type="text"
                            readonly
                        />
                    </el-form-item>
                    <el-form-item
                        label="商品ID:"
                        style="margin-left: 80px; width: 30%; display: inline-block"
                    >
                        <input v-model="formData.commodityid" type="text" readonly />
                    </el-form-item>
                </el-form-item>



                <el-form-item
                    style="border-bottom: 1px solid #ebeef5"
                    label-width="0px"
                >
                    <el-form-item
                        label="封面图:"
                        style="width: 30%; display: inline-block"
                    >
                        <!--<img :src="formData.userpic" alt style="width: 60px;height: 50px">-->
                        <el-popover
                            v-if="formData.commodityicon"
                            placement="right"
                            trigger="hover"
                        >
                            <img
                                :src="formData.commodityicon"
                                style="width: 400px; border-radius: 3px"
                            />
                            <img
                                slot="reference"
                                :src="formData.commodityicon"
                                style="max-height: 80px; max-width: 50px; border-radius: 5px"
                            />
                        </el-popover>
                        <span v-else>-</span>
                    </el-form-item>

                    <el-form-item
                        label="库存:"
                        style="margin-left: 80px; width: 30%; display: inline-block"
                    >
                        <input v-model="formData.commoditynum" type="text" readonly />
                    </el-form-item>
                </el-form-item>
                <!--资质认证-->
                <el-form-item
                    label-width="120px"
                    label="商品资质认证"
                    style="background: #e1e1e1"
                >
                </el-form-item>
                <span v-if="categoryTemplate != [] && categoryTemplate != null">
           <h3 class="thrTitle">{{categoryTemplate.name || ""}}</h3>
            <el-form-item :label="item.fieldname+'：'" :prop="'fieldname'+index" v-for="(item,index) in categoryTemplate.templateItemFormList" :key="item.id">
                <input type="hidden" v-model="item.fieldvalue">
                <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '文字'" type="text" :placeholder="'请填写'+item.fieldname" disabled></el-input>
                <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '数字'" type="number" :placeholder="'请填写'+item.fieldname" disabled></el-input>

                <el-popover v-if="item.fieldtype == '图片'" placement="right" trigger="hover">
                    <img :src="item.fieldvalue" style="width:400px;border-radius:3px;">
                    <img slot="reference" :src="item.fieldvalue" style="max-height: 80px;max-width: 150px;border-radius:5px;">
                </el-popover>
            </el-form-item>
        </span>
                <el-table
                    ref="multipleTable"
                    v-loading="loading"
                    :data="parameterlist"
                    :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
                    @selection-change="handleSelectionChange"
                    border
                >
                    <el-table-column label="商品图片" width="100" align="center">
                        <template slot-scope="scope">
                            <el-popover
                                v-if="scope.row.inventorypic"
                                placement="right"
                                trigger="hover"
                            >
                                <img
                                    :src="scope.row.inventorypic"
                                    style="width: 400px; border-radius: 3px"
                                />
                                <img
                                    slot="reference"
                                    :src="scope.row.inventorypic"
                                    style="max-height: 80px; max-width: 50px; border-radius: 5px"
                                />
                            </el-popover>
                            <span v-else>-</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="规格参数" align="center">
                        <el-table-column
                            v-for="(item, index) in inputData"
                            :key="index"
                            :label="item.key"
                            width="150"
                            align="center"
                        >
                            <template slot-scope="scope">
                                <div v-if="scope.row.splist !== undefined">
                                    <el-select
                                        v-model="scope.row.splist[index]"
                                        placeholder="请选择"
                                        disabled
                                        ref="sel"
                                    >
                                        <el-option
                                            v-for="(it, ind) in item.val.split(',')"
                                            :key="ind"
                                            :label="it"
                                            :value="it"
                                        >
                                        </el-option>
                                    </el-select>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="成本价" prop="costprice"  align="center"/>
                    <!--            <el-table-column label="代理价" prop="primaryagentprice"  align="center"/>-->
                    <el-table-column label="经销价" prop="secondaryagentprice"  align="center"/>
                    <el-table-column label="分销价" prop="commodityprice"  align="center"/>
                    <el-table-column label="零售价" prop="commodityoldprice" align="center"/>
                    <el-table-column label="县域收益占比(%)" prop="profitproportion" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.profitproportion" align="center" disabled
                                :min="0" :controls="false" :precision="4" ></el-input-number>

                            </template>
                    </el-table-column>
                    <el-table-column label="库存" prop="inventorynum" align="center"/>
                </el-table>
                <el-form-item label="商品轮播图:">
                    <div
                        v-for="(item, index) in formData.commoditypiclist"
                        :key="index"
                        style="display: inline-block"
                    >
                        <img
                            :src="item.picurl"
                            style="width: 200px; border-radius: 3px; margin-left: 5px"
                        />
                    </div>
                </el-form-item>

                <el-form-item label="商品详情:">
                    <div v-html="formData.commoditydesc"></div>
                </el-form-item>
            </el-form>
            </el-card>
        </el-dialog>

        <!--add新建编辑-->
        <el-dialog
            :title="formMap[formName]"
            :visible.sync="formVisible"
            :before-close="hideForm"
            width="50%"
            top="5vh"
            v-dialogDrag
            :close-on-click-modal="false"
        >
        <template slot="title">
            <div class="avue-crud__dialog__header">
                <span class="el-dialog__title">
                <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                {{formMap[formName]}}
                </span>
            </div>
        </template>
        <el-card>
            <el-form :model="formData" :rules="formRules" ref="ruleForm">
                <el-form-item
                    label-width="80px"
                    label="基本参数"
                    style="background: #e1e1e1"
                >
                </el-form-item>
                <el-form-item
                    label-width="120px"
                    label="商品名称:"
                    prop="commodityname"
                >
                    <el-input
                        style="width: 50%"
                        v-model="formData.commodityname"
                        placeholder="请输入商品名称"
                        :disabled="true"
                    ></el-input>
                </el-form-item>
                <el-form-item
                    label-width="120px"
                    label="商品分类:"
                    prop="thirdcategoryid"
                >
             <span style="margin-right: 10px;">{{
                  oneCategoryObj.topcategoryname +
                  " --> " +
                  twoCategoryObj.topcategoryname  + " --> "
              }}
          </span>
                    <el-select
                        v-model="formData.thirdcategoryid"
                        placeholder="请选择"
                        @change="thirdchange1(2)"
                        disabled
                    >
                        <el-option
                            v-for="(item, index) in busCommodityThirdCategoryList"
                            :key="index"
                            :disabled="true"
                            :label="item.topcategoryname"
                            :value="item.topcategoryid"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item
                    label-width="120px"
                    label="商品资质认证"
                    style="background: #e1e1e1"
                >
                </el-form-item>
               <span v-if="categoryTemplate != [] && categoryTemplate != null">
                    <h3 style="height: 50px" class="thrTitle">{{categoryTemplate.name || ""}}</h3>
                    <el-form-item label-width="150px" :label="item.fieldname+'：'" :prop="'fieldname'+index" v-for="(item,index) in categoryTemplate.templateItemFormList" :key="item.id">
                        <input type="hidden" v-model="item.fieldvalue">
                        <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '文字'" type="text" :placeholder="'请填写'+item.fieldname"></el-input>
                        <el-input v-model="formData4[item.fieldname]" @input="onInput()" @change="changeInput(item)" v-if="item.fieldtype == '数字'" type="number" :placeholder="'请填写'+item.fieldname"></el-input>
                        <el-upload
                            v-if="item.fieldtype == '图片'"
                            :action="uploadUrl"
                            :on-success="(response, file,fileList)=> handleFieldSuccess(response, file,fileList,'formData4','fieldname' + index,index)"
                            :on-remove="(file,fileList)=> handleFieldPicRemove(file, fileList,'formData4','fieldname' + index,index)"
                            :on-change="(file)=> handleChange(file)"
                            list-type="picture-card"
                            :show-file-list="false"
                            class="avatar-uploader"
                        >
                        <img v-if="item.fieldvalue" :src="item.fieldvalue" class="avatar" style="width: 100%; height: 100%">
                        <i v-else class="el-icon-plus"></i>
                        </el-upload>
                    </el-form-item>
                </span>
                <!--2-->
                <el-form-item
                    label-width="80px"
                    label="规格参数"
                    style="background: #e1e1e1"
                >
                </el-form-item>
                <el-form-item>
                    <div v-for="(item, index) in inputData" :key="index">
                        <el-form-item style="width: 30%; display: inline-grid">
                            <div style="float: none">
                                <el-tag>{{ item.key }}</el-tag>
                                <el-input
                                    v-model="item.val"
                                    placeholder="请输入内容"
                                    :disabled="true"
                                    size="small"
                                />
                            </div>
                        </el-form-item>
                    </div>
                </el-form-item>

                <!--3-->
                <el-form-item
                    label-width="55px"
                    label="库存"
                    style="background: #e1e1e1"
                >
                    <span>{{ formData.commoditynum }}</span>
                </el-form-item>

                <el-form-item>
                    <el-table
                        ref="multipleTable"
                        v-loading="loading"
                        :data="parameterlist"
                        :header-cell-style="{ background: '#F4F4F5', color: '#606266' }"
                        @selection-change="handleSelectionChange"
                        border
                    >
                        <el-table-column label="商品图片" width="100" align="center">
                            <template slot-scope="scope">
                                <el-upload
                                    :disabled="true"
                                    ref="upload"
                                    class="avatar-uploader"
                                    :data="uploadData1"
                                    :action="uploadUrl"
                                    :show-file-list="false"
                                    :on-success="handleAvatarSuccess"
                                >
                                    <img
                                        v-if="scope.row.inventorypic"
                                        :src="scope.row.inventorypic"
                                        class="avatar"
                                        style="width: 50px; height: 50px"
                                    />
                                    <i
                                        v-else
                                        class="el-icon-plus avatar-uploader-icon"
                                        @click="curRowIndex = scope.$index"
                                        style="line-height: 2.3"
                                    ></i>
                                </el-upload>
                            </template>
                        </el-table-column>
                        <el-table-column label="规格参数" align="center">
                            <div v-for="(item, index) in inputData" :key="index">
                                <el-table-column :label="item.key" width="150" align="center">
                                    <template slot-scope="scope">
                                        <div v-if="scope.row.splist !== undefined">
                                            <el-select
                                                v-model="scope.row.splist[index]"
                                                placeholder="请选择"
                                                @change="paramchange($event, scope.$index, item)"
                                            >
                                                <el-option
                                                    :disabled="true"
                                                    v-for="(it, ind) in item.val.split(',')"
                                                    :key="ind"
                                                    :label="it"
                                                    :value="it"
                                                >
                                                </el-option>
                                            </el-select>
                                        </div>
                                    </template>
                                </el-table-column>
                            </div>
                        </el-table-column>
                        <el-table-column label="成本价" prop="costprice"  width="140" align="center" >
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.costprice" placeholder="请输入成本价" :disabled="true" ></el-input>
                            </template>
                        </el-table-column>
                        <!-- 这个是新增的之前是注释的 -->
                        <el-table-column label="代理价(请补充)" prop="primaryagentprice"  width="150" align="center" >
                            <template slot-scope="scope">
                                <el-input  v-model="scope.row.primaryagentprice" placeholder="请补充" ></el-input>
                            </template>
                        </el-table-column>

                        <el-table-column  label="经销价" prop="secondaryagentprice" width="150"  align="center" >
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.secondaryagentprice"  placeholder="请输入经销价" :disabled="true" ></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="分销价" prop="commodityprice" width="140" align="center" >
                            <template slot-scope="scope">
                                <el-input :disabled="true" v-model="scope.row.commodityprice" placeholder="请输入分销价" ></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column  label="零售价"  prop="commodityoldprice"  width="120" align="center" >
                            <template slot-scope="scope">
                                <el-input :disabled="true" v-model="scope.row.commodityoldprice"  placeholder="请输入零售价" clearable ></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="县域收益占比(%)" prop="profitproportion" width="150" align="center">
                            <template slot-scope="scope">
                                <el-input-number style="width: 120px;" v-model="scope.row.profitproportion" align="center" disabled
                                :min="0" :controls="false" :precision="4" ></el-input-number>

                            </template>
                    </el-table-column>
                        <el-table-column label="库存" prop="commoditynum" width="150"  align="center" >
                            <template slot-scope="scope">
                                <el-input :disabled="true" v-model="scope.row.inventorynum" placeholder="请输入商品库存" ></el-input>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form-item>

                <!--3-->
                <el-form-item
                    label-width="65px"
                    label="轮播图"
                    style="background: #e1e1e1"
                >
                </el-form-item>
                <el-form-item style="display: inline-block">
                    <div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
                    <el-upload
                        :disabled="true"
                        :action="uploadUrl"
                        :on-change="handleChange"
                        list-type="picture-card"
                        :on-success="handleSuccess"
                        :on-remove="handlePicRemove"
                        :file-list="uploadData"
                    ><i class="el-icon-plus"></i>
                    </el-upload>
                </el-form-item>
                <el-form-item
                    label-width="80px"
                    label="商品详情"
                    style="background: #e1e1e1"
                ></el-form-item>
            </el-form>
            <div>
                <!-- 图片上传组件辅助-->
                <el-upload
                    class="edituploader"
                    :action="uploadUrl"
                    :show-file-list="false"
                    :on-success="imguploadSuccess"
                    :on-error="uploadError"
                    :before-upload="beforeUpload"
                >
                </el-upload>
                <quill-editor
                    :aria-disabled="true"
                    v-model="formData.commoditydesc"
                    ref="myQuillEditor"
                    :options="editorOption"
                    @change="onEditorChange($event)"
                    @focus="onEditorFocus($event)"
                >
                </quill-editor>
            </div>
            </el-card>

            <div slot="footer" class="dialog-footer">
                <el-button @click.native="hideForm">取消</el-button>
                <el-button
                    type="primary"
                    @click.native="formSubmit()"
                    :loading="formLoading"
                >提交</el-button
                >
            </div>
        </el-dialog>
        </el-card>
    </div>
</template>
<script>
    import {
        getAddList,
        delBusCommodity,
        addBusCommodity,
        addBusCommodity1,
        // insertCommodityInventory,
        updateBusCommodity,
        getGoodsCertificationInfo,
    } from "../../api/buscommodity/buscommodity.js";
    import Tinymce from "../../components/Tinymce/index.vue";
    import { BASE_URL } from "../../config/app";

    import { quillEditor } from "vue-quill-editor"; //调用编辑器
    import "quill/dist/quill.core.css";
    import "quill/dist/quill.snow.css";
    import "quill/dist/quill.bubble.css";
    import {getMainCategoryMap} from "../../api/buscommodity/buscommodity";
    /*用作表单的数据初始化*/
    const formJson = {
        commodityid: "", //商品id
        commodityname: "", //商品名称
        recommendstatus: 0, //商品'0不推荐1推荐',
        onshelfstatus: 1, //商品 0全部，  1不上架 2上架',
        commodityicon: "", //商品图片
        commodityprice: "", // 售价    decimal(20,2),
        commodityoldprice: "", //商品原价    decimal(20,2),
        commodityfrom: "", // 货源地
        topcategoryname: "", //一级分类
        secondarycategoryname: "", //二级分类
        thirdcategoryname: "", //三级分类
        commoditynum: "", // 库存
        createtime: "", // 添加时间
        commoditydesc: "", //商品描述
        commoditypiclist: [], //图片
        piclist: "", //图片列表
        videopic: "", //视频地址

        /**/
        topcategoryid: "", //一级分类id',
        secondarycategoryid: "", //二级分类id',
        thirdcategoryid: "", // 三级分类id,

        inids: "", //参数id
        param: "",
        inputdata: "", //全部参数
        certificationcontent: "",
    };
    const toolbarOptions = [
        ["bold", "italic", "underline", "strike"], // toggled buttons
        [{ header: 1 }, { header: 2 }], // custom button values
        [{ list: "ordered" }, { list: "bullet" }],
        [{ indent: "-1" }, { indent: "+1" }], // outdent/indent
        [{ direction: "rtl" }], // text direction
        [{ size: ["small", false, "large", "huge"] }], // custom dropdown
        [{ header: [1, 2, 3, 4, 5, 6, false] }],
        [{ color: [] }, { background: [] }], // dropdown with defaults from theme
        [{ font: [] }],
        [{ align: [] }],
        ["link", "image"],
        ["clean"],
    ];
    export default {
        components: {
            Tinymce,
            quillEditor,
        },
        data() {
            return {
                iskip: true,
                isSkip: false, // 判断是否是从品牌代理商商品页面跳转过来的
                categoryTemplate: [], // 商品类目模板
                emptyTemplate: [], //空模板
                inventoryVisible: false, //库存管理编辑显示
                query: {
                    //查询条件
                    content: "",
                    starttime: "",
                    endtime: "",
                    onshelfstatus: "0", //0全部，  1不上架 2上架
                    recommendstatus: "", //0不推荐1推荐
                    currentPage: 1,
                    pageSize: 10,
                    thirdcategoryid: "", //三级
                },
                formData: formJson, //新增或修改的对象
                commoditypiclist: [],
                formName: "",
                formMap: {
                    add: "添加",
                    edit: "编辑",
                    detail: "查看",
                    inventoryEdit: "库存管理"
                },
                uploadUrl: BASE_URL + '/goldendays-currency/tool/uploadpro', //上传图片
                uploadvideo: BASE_URL + "/tool/uploadVideo", //上传视频
                uploadData: [], //[{name:"12",url:"http://localhost/maotianxiaupload/common/2019-08-23/MH1566545692219_mid.jpg"}], // 图片data
                vuploadData: [], //视频
                uploadData1: {}, // 图片data
                curRowIndex: 0, //图片row
                createTime: [], //选择日期时需要的model
                list: [], //列表集合
                parameterlist: [], //add参数list
                oneCategoryObj:{},
                twoCategoryObj:{},

                //savadd参数list
                category: [], //分类列表
                buswarehouse: [], //仓库列表
                busCommoditySecondaryCategoryList: [], //二级
                busCommodityThirdCategoryList: [], //三级
                categoryobj: {}, //分类列表
                SecondaryCategoryobj: {}, //二级
                ThirdCategoryobj: {}, //三级
                inputData: [], // 循环创建input存值
                totalNumber: 0, //分页总页数
                formVisible: false, //添加编辑显示
                loading: true, //列表加载
                dis: true, //不可点击
                formLoading: false, //表单提交加载
                allLoding: false, //全屏加载
                cancelToggle: false,
                detailVisible: false, //查看
                classification: false,
                multipleSelection: [], //多选集合
                formRules: {
                    commodityname: {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur",
                    },
                    thirdcategoryid: {
                        required: true,
                        message: "请选择分类",
                        trigger: "blur",
                    },
                    /*commodityprice: {
                      required: true,
                      message: "请输入售价",
                      trigger: "blur",
                    },
                    commodityoldprice: {
                      required: true,
                      message: "请输入代理价",
                      trigger: "blur",
                    },*/
                    commoditydesc: {
                        required: true,
                        message: "请输入商品详情",
                        trigger: "blur",
                    },
                },
                formData4: {
                    // 第四步表单
                    storename: null, // 店铺名称
                    enterinfoid: null, // 主键
                    certificationcontent: null, // 商品分类模板
                    topcategoryid: null, // 一级商品分类id
                    secondarycategoryid: null, // 二级商品分类id
                    categoryid: null, // 三级商品分类id
                },
                quillUpdateImg: false, // 根据图片上传状态来确定是否显示loading动画，刚开始是false,不显示
                // content: null,
                editorOption: {
                    placeholder: "",
                    theme: "snow", // or 'bubble'
                    modules: {
                        toolbar: {
                            container: toolbarOptions,
                            handlers: {
                                image: function (value) {
                                    if (value) {
                                        // 触发input框选择图片文件
                                        document.querySelector(".edituploader input").click();
                                    } else {
                                        this.quill.format("image", false);
                                    }
                                },
                            },
                        },
                    },
                },
                //serverUrl: '/manager/common/imgUpload', // 这里写你要上传的图片服务器地址
                header: {
                    // token: sessionStorage.token
                },
            };
        },
        watch: {},
        methods: {
            //图片上传成功
            handleFieldSuccess(response, file, fileList, index, key, item) {
                if (response.status === 1) {
                    this[index][key] = response.data;
                    if (item || item == 0) {
                        // item.fieldvalue = this.formData4[item.fieldname];
                        this.categoryTemplate.templateItemFormList[
                            item
                            ].fieldvalue = this.formData4[key];
                        console.log(
                            this.categoryTemplate.templateItemFormList[item]
                        );
                        console.log(this.formData4);
                    }
                    return;
                }
                this.$message.error("上传文件报错");
            },
            // 移除图片
            handleFieldPicRemove(file, fileList, index, key, item) {
                this[index][key] = null;
                if (item || item == 0) {
                    // item.fieldvalue = null;
                    this.categoryTemplate.templateItemFormList[
                        item
                        ].fieldvalue = null;
                    console.log(this.categoryTemplate.templateItemFormList[item]);
                    console.log(this.formData4);
                }
            },
            onEditorFocus(event) {
                event.enable(false);
            },
            //图片上传成功
            handleFormDataSuccess(response, file, fileList, index, key, item) {
                if (response.status === 1) {
                    this[index][key] = response.data;
                    if (item) {
                        item.fieldvalue = this.formData4[item.fieldname];
                    }
                    return;
                }
                this.$message.error("上传文件报错");
            },
            // 强制刷新input
            onInput() {
                this.$forceUpdate();
            },
            // 模板input监听
            changeInput(val) {
                val.fieldvalue = this.formData4[val.fieldname];
                console.log(this.formData4);
            },
            getBrandList() {},
            onEditorChange({ editor, html, text }) {
                console.log(editor);
                console.log(text);
                //内容改变事件
                console.log("---内容改变事件---");
                this.formData.commoditydesc = html;
                console.log(html);
            },
            // 富文本图片上传前
            beforeUpload() {
                // 显示loading动画
                this.quillUpdateImg = true;
            },

            imguploadSuccess(response, file) {
                console.log(file);
                // res为图片服务器返回的数据
                // 获取富文本组件实例
                console.log(response);
                let quill = this.$refs.myQuillEditor.quill;

                // 如果上传成功
                if (response.status === 1) {
                    let filePath = response.data;
                    // 获取光标所在位置
                    let length = quill.getSelection().index;
                    // 插入图片 res.url为服务器返回的图片地址
                    quill.insertEmbed(length, "image", filePath);
                    // 调整光标到最后
                    quill.setSelection(length + 1);
                    this.$message.success("图片插入成功");
                } else {
                    this.$message.error("图片插入失败");
                }
                // loading动画消失
                this.quillUpdateImg = false;
            },
            // 富文本图片上传失败
            uploadError() {
                // loading动画消失
                this.quillUpdateImg = false;
                this.$message.error("图片插入失败");
            },
            //table列表参数
            paramchange(e, i, it) {
                console.info(
                    999999999999 + "=====" + e + "=====" + i + "=====" + JSON.stringify(it)
                );
                for (let j = 0; j < this.parameterlist.length > 0; j++) {
                    for (let i = 0; i < this.parameterlist[j].splist.length; i++) {
                        if (this.parameterlist[j].splist[i] === e) {
                            // this.parameterlist[j].savparameterlist[i]=JSON.stringify(it)
                            let data = {};
                            this.$set(data, it.key, e);
                            this.parameterlist[j].savparameterlist[i] = data;
                            console.info(this.parameterlist[j].savparameterlist);
                        }
                    }
                }
            },

            //仓库
            warechange(e) {
                for (let i = 0; i < this.buswarehouse.length; i++) {
                    if (e === this.buswarehouse[i].warehouseid) {
                        this.formData.commodityfrom = this.buswarehouse[i].warehousename;
                        this.formData.warehouseid = this.buswarehouse[i].warehouseid;
                    }
                }

                // alert(e.warehousename)
            },
            formSubmit() {
                console.log(this.parameterlist);
                let plist = this.parameterlist;

                for (let i = 0; i < plist.length; i++) {
                    let jsonval = JSON.stringify(plist[i].savparameterlist);
                    let json = plist[i].savparameterlist;
                    let indata = {};
                    for (var j = 0, l = json.length; j < l; j++) {
                        for (var key in json[j]) {
                            // alert(key+':'+json[j][key]);
                            this.$set(indata, key, json[j][key]);
                        }
                    }
                    plist[i].inventory = JSON.stringify(indata);
                    plist[i].secinventory = jsonval;
                }

                //表单校验通过
                this.$refs["ruleForm"].validate((valid) => {
                    if (valid) {
                        //this.formLoading = true;
                        // let mids="";
                        /*     for (let i = 0; i < plist.length; i++) {
                                          var par = new URLSearchParams(plist[i]);
                                          /!*添加参数*!/
                                          insertCommodityInventory(par).then(response => {
                                             // this.formLoading = false;
                                              console.info("参数a："+response.data)
                                              if (response.code != 0) {
                                                  this.$message.error(response.message);
                                                  return false;
                                              }
                                              if (mids === '') {
                                                  mids = response.data;
                                              } else {
                                                  mids = mids + "," + response.data;
                                              }
                                              this.$message.success("操作成功");

                                          }).catch(() => {
                                             // this.formLoading = false;
                                              this.formVisible = false;
                                          });

                                      }*/

                        /*添加商品*/
                        // alert(mids);
                        if (
                            this.formData.commoditypiclist &&
                            this.formData.commoditypiclist.length !== 0
                        ) {
                            this.formData.commodityicon = this.formData.commoditypiclist[0];
                            this.formData.piclist = this.formData.commoditypiclist.join(",");
                        }
                        /*if (plist) {
                          let num = 0;
                          for (let i = 0; i < plist.length; i++) {
                            let nm = 1;
                            num += plist[i].inventorynum * nm;
                          }

                          this.formData.commoditynum = num;
                          this.formData.commodityprice = plist[0].commodityoldprice;
                          this.formData.commodityoldprice = plist[0].primaryagentprice;
                        }*/
                        if(plist){
                            let num=0;
                            for (let i=0;i< plist.length;i++) {
                                let nm=1;
                                num+=(plist[i].inventorynum)*(nm);
                                /*var inventory=  plist[i].inventory.substring(1,plist[i].inventory.length-1);
                                var inventorylist=inventory.split(":");
                                console.info(inventorylist[1].length)
                                if(inventorylist[1].length<3){
                                    this.$message.warning("请完善商品规格信息！");
                                    return false;
                                }*/
                                if(plist[i].primaryagentprice <1){
                                    this.$message.warning("请补充商品规格中代理价！");
                                    return false;
                                }
                            }

                            this.formData.commoditynum = num;
                            this.formData.commodityprice = plist[0].commodityoldprice;
                            this.formData.commodityoldprice = plist[0].primaryagentprice;
                        }
                        /*commodityprice: {
                                  required: true,
                                  message: "请输入售价",
                                  trigger: "blur",
                                },
                                commodityoldprice: {
                                  required: true,
                                  message: "请输入代理价",
                                  trigger: "blur",
                                },*/

                        this.formData.param = JSON.stringify(plist);
                        //alert(JSON.stringify(this.inputData));
                        this.formData.inputdata = JSON.stringify(this.inputData);
                        let flag = false;
                        var msg ="";
                        if(this.categoryTemplate==null ||  this.categoryTemplate==undefined) {
                            this.$message.warning("无商品模板！");
                            return false;
                        }
                        this.formData.certificationcontent = JSON.stringify(this.categoryTemplate);
                        if(this.categoryTemplate.templateItemFormList!=null&&this.categoryTemplate.templateItemFormList!=undefined){
                            this.categoryTemplate.templateItemFormList.forEach(item => {
                                    if((item.fieldvalue==null||item.fieldvalue=="")&& item.ismust==0){
                                        msg = item.fieldname;
                                        flag = true;
                                    }
                                }
                            );
                        }else{
                            this.$message.warning("无商品模板！");
                            return false;
                        }
                        if(flag){
                            this.$message({
                                message: msg+"不能为空！",
                                type: "warning"
                            });
                            return false;
                        }
                        var params = new URLSearchParams(this.formData);
                        if (this.iskip) {
                            addBusCommodity1(params)
                                .then((response) => {
                                    this.formLoading = true;
                                    if (response.code != 0) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("操作成功");
                                    this.uploadData = []; //图片
                                    this.vuploadData = []; //视频

                                    this.formData = {};
                                    // this.$refs.tinymce.setContent("");

                                    this.formLoading = false;
                                    this.formVisible = false;

                                    this.dis = true;
                                    // 加载表格数据
                                    this.getList();
                                    // 清空表单
                                    this.$refs["ruleForm"].resetFields();
                                    //取消
                                    this.closeCategory();
                                })
                                .catch(() => {
                                    this.formLoading = false;
                                    this.formVisible = false;
                                    this.dis = true;
                                });
                            return;
                        }

                        addBusCommodity(params)
                            .then((response) => {
                                this.formLoading = true;
                                if (response.code != 0) {
                                    this.$message.error(response.message);
                                    return false;
                                }
                                this.$message.success("操作成功");
                                this.uploadData = []; //图片
                                this.vuploadData = []; //视频

                                this.formData = {};
                                // this.$refs.tinymce.setContent("");

                                this.formLoading = false;
                                this.formVisible = false;

                                this.dis = true;
                                // 加载表格数据
                                this.getList();
                                // 清空表单
                                this.$refs["ruleForm"].resetFields();
                                //取消
                                this.closeCategory();
                            })
                            .catch(() => {
                                this.formLoading = false;
                                this.formVisible = false;
                                this.dis = true;
                            });
                    }
                });
            },
            /*----------*/
            //列表
            handleAvatarSuccess(response, file) {
                console.log(file);
                this.isSelect = false;
                if (response.status === 1) {
                    const filePath = response.data;
                    //alert(this.curRowIndex+"--"+filePath);
                    this.parameterlist[this.curRowIndex].inventorypic = filePath;
                    return;
                }
                this.$message.error("上传文件报错");
            },
            // 图片上传
            AvatarUpload(file) {
                this.fileName = file.name ? file.name : "";
                return false;
            },
            //图片上传成功
            vhandleSuccess(response, file) {
                console.log(file);
                this.isSelect = false;
                if (response.status === 1) {
                    const filePath = response.data; //视频地址
                    const vPath = response.content; //视频截图地址
                    console.log(vPath);
                    this.formData.videopic = filePath;
                    // console.info(JSON.stringify(this.uploadData));
                    return;
                }

                this.$message.error("上传文件报错");
            },
            // 图片上传
            vhandleChange(file) {
                this.fileName = file.name ? file.name : "";
                return false;
            },
            //图片上传成功
            handleSuccess(response, file) {
                console.log(file);
                console.info(response);
                this.isSelect = false;
                if (response.status === 1) {
                    const filePath = response.data;
                    this.commoditypiclist.push(filePath);
                    this.formData.commoditypiclist = this.commoditypiclist;
                    //this.formData.commoditypiclist=this.uploadData;
                    console.info(JSON.stringify(this.uploadData));
                    return;
                }

                this.$message.error("上传文件报错");
            },
            // 图片上传
            handleChange(file) {
                this.fileName = file.name ? file.name : "";
                return false;
            },
            handlePicRemove(file, fileList) {
                console.info("file=" + file + "fileList:" + fileList);
                console.info(
                    "commoditypiclist" + JSON.stringify(this.formData.commoditypiclist)
                );
                var url = "";
                url = file.url;
                // alert(url)
                for (var i = 0; i < this.formData.commoditypiclist.length; i++) {
                    //alert(this.formData.commoditypiclist[i])
                    if (url === this.formData.commoditypiclist[i]) {
                        // alert(i+"===="+this.formData.commoditypiclist[i])
                        this.formData.commoditypiclist.splice(i, 1);
                        // alert(i+"===="+this.formData.commoditypiclist[i]+"==")
                        console.info(
                            "commoditypiclist9999999999" +
                            JSON.stringify(this.formData.commoditypiclist)
                        );
                        //this.commoditypiclist.splice(i, 1)
                    }
                }
                for (let i = 0; i < this.uploadData.length; i++) {
                    //alert(this.formData.commoditypiclist[i])
                    if (url === this.uploadData[i].url) {
                        // alert(i+"===="+this.formData.commoditypiclist[i])
                        this.uploadData.splice(i, 1);
                        // alert(i+"===="+this.formData.commoditypiclist[i]+"==")
                        console.info(
                            "commoditypiclist9999999999" +
                            JSON.stringify(this.formData.commoditypiclist)
                        );
                        //this.commoditypiclist.splice(i, 1)
                    }
                }
                console.info(this.uploadData);
            },

            //添加参数
            addpara() {
                let param = {
                    inventoryid: "", //          bigint not null auto_increment,
                    commodityid: "", //          bigint,
                    inventory: "", //      规格参数      text,
                    secinventory: "", //规格参数2
                    commodityprice: 0, //    分销价   decimal(20,2),
                    commodityoldprice: 0, //  零售价  decimal(20,2),
                    // primaryagentprice: 0, //一级代理
                    secondaryagentprice: 0, //二级代理
                    costprice: 0, //成本价
                    inventorynum: 0, //      库存   int,
                    inventorypic: "", //   规格图片      varchar(200),
                    companytype: 0, //      单位    smallint comment '0:瓶 1箱 2:套',
                    boxnum: "", //      每箱瓶数         int comment '每箱瓶数',
                    savparameterlist: [],
                    splist: [],
                };
                let p = {
                    key: "",
                    val: "",
                };
                param.savparameterlist.push(p);
                this.parameterlist.push(param);
                console.info("++" + this.parameterlist[0].savparameterlist.val);
            },
            //删除
            paraDel(index, row) {
                console.log(row);
                this.parameterlist.splice(index, 1);
            },
            //关闭分类
            closeCategory() {
                this.classification = false;
                this.formData.topcategoryid = "";
                this.formData.secondarycategoryid = "";
                this.formData.thirdcategoryid = "";

                this.categoryobj = {};
                this.ThirdCategoryobj = {};
                this.SecondaryCategoryobj = {};
                this.inputData = [];
            },
            //add分类
            chosebtn() {
                this.classification = true;
            },
            //查看评论
            lookcomment(v) {
                this.$router.push({
                    path: "/commodity/comment",
                    query: { cid: v },
                });
                // alert(v)
            },
            //add 隐藏表单
            hideForm() {
                // 更改值
                this.formVisible = !this.formVisible;
                // 清空表单
                this.$refs["ruleForm"].resetFields();

                this.query.warehousename = "";
                return true;
            },
            /* --------------*/
            //筛选上架
            shelfstatus() {
                //  alert(this.query.onshelfstatus);
                if (this.query.onshelfstatus === "0") {
                    this.$router.push({
                        path: "",
                    });
                    //刷新事件需要重置查询条件
                    this.createTime = [];
                    this.query = {
                        currentPage: 1,
                        pageSize: 10,
                    };
                    this.getList();
                } else {
                    this.query.currentPage = 1;
                    this.$router.push({
                        path: "",
                        query: this.query,
                    });
                    this.getList();
                }
            },
            //上架
            onshelfschange(row) {
                this.loading = true;
                var params = new URLSearchParams();
                params.append("commodityid", row.commodityid);
                params.append("onshelfstatus", row.onshelfstatus);
                updateBusCommodity(params)
                    .then((response) => {
                        this.loading = false;
                        if (response.code) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.loading = false;
                        this.$message.success("更新成功");
                        // 刷新数据
                    })
                    .catch(() => {
                        this.loading = false;
                    });
            },
            //推荐
            recommendchange(row) {
                this.loading = true;
                var params = new URLSearchParams();
                params.append("commodityid", row.commodityid);
                params.append("recommendstatus", row.recommendstatus);
                updateBusCommodity(params)
                    .then((response) => {
                        this.loading = false;
                        if (response.code) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.loading = false;
                        this.$message.success("更新成功");
                        // 刷新数据
                    })
                    .catch(() => {
                        this.loading = false;
                    });
            },
            // 显示表单
            handleForm() {
                this.categoryTemplate = [];
                this.formVisible = true;
                this.formName = "add";
                this.inputData = [];
                this.parameterlist = [];
                this.uploadData = [];
                //this.commoditydesc=""//this.$refs.tinymce.setContent("");
                this.formData = {
                    commodityid: "", //商品id
                    commodityname: "", //商品名称
                    recommendstatus: 0, //商品'0不推荐1推荐',
                    onshelfstatus: 1, //商品 0全部，  1不上架 2上架',
                    commodityicon: "", //商品图片
                    commodityprice: "", // 售价    decimal(20,2),
                    commodityoldprice: "", //商品原价    decimal(20,2),
                    commodityfrom: "", // 货源地
                    topcategoryname: "", //一级分类
                    secondarycategoryname: "", //二级分类
                    thirdcategoryname: "", //三级分类
                    primaryentitybillie: "",
                    seniorentitybillie: "",
                    commoditytype: "",
                    commoditynum: "", // 库存
                    createtime: "", // 添加时间
                    commoditydesc: "", //商品描述
                    commoditypiclist: [], //图片
                    piclist: "", //图片列表
                    videopic: "", //视频地址
                    topcategoryid: "", //一级分类id',
                    secondarycategoryid: "", //二级分类id',
                    thirdcategoryid: "", // 三级分类id,

                    inids: "", //参数id
                    param: "",
                    inputdata: "", //全部参数
                };
            },

            //显示 查看弹框
            detailForm(index, row) {
                this.detailVisible = true;
                if (row !== null) {
                    this.inputData = [];
                    this.formData = Object.assign({}, row);
                    console.info(row);
                    console.info(this.formData);
                    this.formData.secondarycategoryid = row.secondarycategoryid;
                    this.formData.thirdcategoryid = row.thirdcategoryid;
                    if (row.certificationcontent != null) {
                       let _this = this;
                        _this.categoryTemplate = JSON.parse(row.certificationcontent);
                        this.formData.certificationcontent = JSON.parse(
                            row.certificationcontent
                        );
                        if(this.categoryTemplate.templateItemFormList!=null &&this.categoryTemplate.templateItemFormList!=undefined) {
                            this.categoryTemplate.templateItemFormList.forEach((item) => {
                                // item.fieldvalue = this.formData4[item.fieldname];
                                this.formData4[item.fieldname] = item.fieldvalue;
                            });
                        }
                    }
                    // this.formData.commoditytype=row.commoditytype+"";
                    if (
                        row.inventorylist != null &&
                        row.inventorylist[0].inputdata != null
                    ) {
                        this.inputData = JSON.parse(row.inventorylist[0].inputdata);
                    } else {
                        let data = {
                            key: "",
                            val: "",
                        };
                        this.inputData.push(data);
                    }
                }
                let data = [];
                let pic = [];
                let vdata = [];
                let vpic = [];
                for (let i = 0; i < row.commoditypiclist.length; i++) {
                    let picdata = row.commoditypiclist[i];
                    if (picdata.recoursetype === 0) {
                        let obj = {
                            name: "",
                            url: "",
                        };
                        obj.name = i;
                        obj.url = picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl);
                    }
                    if (picdata.recoursetype === 1) {
                        let obj = {
                            name: "",
                            url: "",
                        };
                        obj.name = i;
                        obj.url = picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl);
                    }
                }

                this.formData.videopic = vpic;
                this.vuploadData = vdata;
                this.commoditypiclist = pic;
                this.formData.commoditypiclist = pic;
                this.uploadData = data;

                this.parameterlist = row.inventorylist;
                for (let i = 0; i < this.parameterlist.length; i++) {
                    let sav = [];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a = this.parameterlist[i].inventory.indexOf("}");
                    var b = this.parameterlist[i].inventory.substring(1, a);
                    var a1 = b.split(",");
                    var splist1 = [];
                    for (let c = 0; c < a1.length; c++) {
                        var s = a1[c]
                            .split(":")[1]
                            .substring(1, a1[c].split(":")[1].length - 1);
                        splist1.push(s);
                    }

                    //县域百分比回显
                    if( this.parameterlist[i].profitproportion<1){
                        (this.parameterlist[i].profitproportion)*= 100;
                    }else{
                        (this.parameterlist[i].profitproportion)
                    }
                    this.parameterlist[i].splist = splist1;
                    this.parameterlist[i].savparameterlist = JSON.parse(
                        this.parameterlist[i].secinventory
                    );

                    this.parameterlist[i].companytype = this.parameterlist[
                        i
                        ].companytype.toString();
                }
                //参数
                let sav = [];
                if (this.parameterlist != null && this.parameterlist.length > 0) {
                    for (let i = 0; i < this.parameterlist.length; i++) {
                        let pdata = JSON.parse(this.parameterlist[i].secinventory);

                        console.info(pdata);

                        for (let i = 0; i < pdata.length; i++) {
                            let mdata = pdata[i];
                            for (let v in mdata) {
                                let data = {
                                    key: v,
                                    val: mdata[v].toString(),
                                };
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist = pdata;
                    }
                    this.parameterlist.splist = sav;
                }
                this.formName = "detail";
            },

            // 隐藏详情弹框
            hideDetailForm() {
                // 更改值
                this.detailVisible = !this.detailVisible;
                return true;
            },
            hideclassification() {
                this.classification = !this.classification;
                return true;
            },

            //编辑
            editForm(index, row) {
                this.formVisible = true;
                this.formData = Object.assign({}, formJson);
                if (row.certificationcontent != null) {
                    var ss = Object.assign({}, row);
                    this.categoryTemplate = JSON.parse(ss.certificationcontent);
                    console.log(
                        this.categoryTemplate,
                        "this.categoryTemplate.templateItemFormList"
                    );
                    this.formData.certificationcontent = JSON.parse(
                        row.certificationcontent
                    );
                    if(this.categoryTemplate.templateItemFormList!=null &&this.categoryTemplate.templateItemFormList!=undefined) {
                        this.categoryTemplate.templateItemFormList.forEach((item) => {
                            // item.fieldvalue = this.formData4[item.fieldname];
                            this.formData4[item.fieldname] = item.fieldvalue;
                        });
                    }
                } else {
                    _this.categoryTemplate = this.emptyTemplate;
                }
                if (row !== null) {
                    this.inputData = [];
                    this.formData = Object.assign({}, row);

                    if (
                        row.inventorylist != null &&
                        row.inventorylist[0].inputdata != null
                    ) {
                        console.info("inputdate", row.inventorylist[0].inputdata);
                        this.inputData = JSON.parse(row.inventorylist[0].inputdata);
                        console.info(this.inputData);
                        /*      this.inputData.sort(function (a,b) {
                                            return(a<b)
                                        })*/
                    } else {
                        let data = {
                            key: "",
                            val: "",
                        };
                        this.inputData.push(data);
                    }
                }
                let data = [];
                let pic = [];
                let vdata = [];
                let vpic = [];
                for (let i = 0; i < row.commoditypiclist.length; i++) {
                    let picdata = row.commoditypiclist[i];
                    if (picdata.recoursetype === 0) {
                        let obj = {
                            name: "",
                            url: "",
                        };
                        obj.name = i;
                        obj.url = picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl);
                    }
                    if (picdata.recoursetype === 1) {
                        let obj = {
                            name: "",
                            url: "",
                        };
                        obj.name = i;
                        obj.url = picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl);

                        //vurl=picdata.videopic;
                    }
                }

                this.formData.videopic = vpic;
                this.vuploadData = vdata;
                this.commoditypiclist = pic;
                this.formData.commoditypiclist = pic;
                this.uploadData = data;

                // alert(JSON.stringify(row));

                this.parameterlist = row.inventorylist;
                console.info("parameterlist111111", this.parameterlist);
                for (let i = 0; i < this.parameterlist.length; i++) {
                    let sav = [];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    console.info("pppppppp", this.parameterlist[i].inventory);
                    var a = this.parameterlist[i].inventory.indexOf("}");
                    var b = this.parameterlist[i].inventory.substring(1, a);
                    var a1 = b.split(",");
                    var splist1 = [];
                    for (let c = 0; c < a1.length; c++) {
                        var s = a1[c]
                            .split(":")[1]
                            .substring(1, a1[c].split(":")[1].length - 1);
                        splist1.push(s);
                    }
                    //县域百分比回显
                    if( this.parameterlist[i].profitproportion<1){
                        (this.parameterlist[i].profitproportion)*= 100;
                    }else{
                        (this.parameterlist[i].profitproportion)
                    }
                    this.parameterlist[i].splist = splist1;
                    this.parameterlist[i].savparameterlist = JSON.parse(
                        this.parameterlist[i].secinventory
                    );

                    this.parameterlist[i].companytype = this.parameterlist[
                        i
                        ].companytype.toString();
                    // this.parameterlist[i].splist=splist1;
                    // console.info("qqqqqqqqqqqqq",this.parameterlist[i].splist)
                    // this.ref.sel.$forceUpdate();
                }

                //console.info("99999999999999",this.inputData);
                /*------------------*/
                //参数
                let sav = [];
                if (this.parameterlist != null && this.parameterlist.length > 0) {
                    for (let i = 0; i < this.parameterlist.length; i++) {
                        let pdata = JSON.parse(this.parameterlist[i].secinventory);

                        console.info(pdata);

                        for (let i = 0; i < pdata.length; i++) {
                            let mdata = pdata[i];
                            for (let v in mdata) {
                                // let data = {
                                //     key: v,
                                //     val: mdata[v].toString()
                                // };
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist = pdata;
                    }
                    this.parameterlist.splist = sav;
                }

                this.formName = "edit";
                /*三级*/
                for (var k = 0; k < this.busCommodityThirdCategoryList.length; k++) {
                    if (
                        this.busCommodityThirdCategoryList[k].thirdcategoryid ==
                        this.formData.thirdcategoryid
                    ) {
                        this.ThirdCategoryobj = this.busCommodityThirdCategoryList[k];

                        this.formData.thirdcategoryname = this.busCommodityThirdCategoryList[
                            k
                            ].thirdcategoryname;

                        break;
                    }
                }
            },

            inventoryForm(index, row) {
                console.info('---row--Data:'+ JSON.stringify(row));
                this.inventoryVisible = true;
                if (row !== null) {
                    this.inputData=[]
                    this.formData = Object.assign({}, row);
                    this.formData.secondarycategoryid=row.secondarycategoryid;
                    this.formData.thirdcategoryid=row.thirdcategoryid;
                    let id=row.warehouseid
                    this.formData.warehouseid=id;
                    let  postagetype=row.postagetype+"";
                    this.formData.postagetype=postagetype;
                    // this.formData.commoditytype=row.commoditytype+"";
                    if(row.inventorylist!=null&&row.inventorylist[0].inputdata!=null){
                        this.inputData=JSON.parse(row.inventorylist[0].inputdata);
                    }else{
                        let data={
                            key:"",
                            val:""
                        }
                        this.inputData.push(data);
                    }
                }
                let data=[];
                let pic=[];
                let vdata=[];
                let vpic=[];
                for (let i=0;i<row.commoditypiclist.length;i++){
                    let picdata=row.commoditypiclist[i];
                    if(picdata.recoursetype===0){
                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        data.push(obj);
                        pic.push(picdata.picurl)
                    }
                    if(picdata.recoursetype===1){

                        let obj={
                            name:"",
                            url:""
                        }
                        obj.name=i;
                        obj.url=picdata.picurl;
                        vdata.push(obj);
                        vpic.push(picdata.picurl)
                    }
                }

                this.formData.videopic=vpic;
                this.vuploadData=vdata
                this.commoditypiclist=pic;
                this.formData.commoditypiclist=pic;
                this.uploadData=data;

                this.parameterlist=row.inventorylist;
                for(let i=0;i<this.parameterlist.length;i++){
                    let sav=[];
                    this.$set(this.parameterlist[i], "savparameterlist", sav);
                    this.$set(this.parameterlist[i], "splist", sav);

                    var a=this.parameterlist[i].inventory.indexOf("}");
                    var b=this.parameterlist[i].inventory.substring(1,a)
                    var a1=b.split(",");
                    var splist1=[];
                    for (let c=0;c<a1.length;c++) {
                        var s=a1[c].split(":")[1].substring(1,a1[c].split(":")[1].length-1);
                        splist1.push(s)
                    }
                    this.parameterlist[i].splist=(splist1);
                    this.parameterlist[i].savparameterlist=JSON.parse(this.parameterlist[i].secinventory);

                    this.parameterlist[i].companytype= this.parameterlist[i].companytype.toString();
                }
                //参数
                let sav=[];
                if(this.parameterlist!=null&&this.parameterlist.length>0){

                    for(let i=0;i<this.parameterlist.length;i++){
                        let pdata=JSON.parse(this.parameterlist[i].secinventory);

                        console.info(pdata)

                        for (let i=0;i<pdata.length;i++) {
                            let mdata=pdata[i]
                            for (let v in mdata){
                                let data={
                                    key:v,
                                    val:mdata[v].toString()
                                }
                                sav.push(mdata[v].toString());
                            }
                        }
                        this.parameterlist.savparameterlist=pdata;
                    }
                    this.parameterlist.splist=sav;
                }
                this.formName = "inventoryEdit";
                console.info('--parameterlist-data:'+ JSON.stringify(this.parameterlist));
            },
            //添加参数
            addpara() {
                let param = {
                    inventoryid: "", //          bigint not null auto_increment,
                    commodityid: "", //          bigint,
                    inventory: "", //      规格参数      text,
                    secinventory: "", //规格参数2
                    commodityprice: 0, //    分销价   decimal(20,2),
                    commodityoldprice: 0, //  零售价  decimal(20,2),
                    primaryagentprice: 0, //代理价格 新增的 之前是注释的
                    secondaryagentprice: 0, //二级代理
                    costprice: 0, //成本价
                    inventorynum: 0, //      库存   int,
                    inventorypic: "", //   规格图片      varchar(200),
                    companytype: 0, //      单位    smallint comment '0:瓶 1箱 2:套',
                    boxnum: "", //      每箱瓶数         int comment '每箱瓶数',
                    savparameterlist: [],
                    splist: []
                };
                let p = {
                    key: "",
                    val: ""
                };
                param.savparameterlist.push(p);
                this.parameterlist.push(param);
                console.info("++" + this.parameterlist[0].savparameterlist.val);
            },
            //删除
            paraDel(index, row) {
                console.log(row);
                this.parameterlist.splice(index, 1);
            },
            //筛选上架
            shelfstatus() {
                //  alert(this.query.onshelfstatus);
                if (this.query.onshelfstatus === "0") {
                    this.$router.push({
                        path: "",
                    });
                    //刷新事件需要重置查询条件
                    this.createTime = [];
                    this.query = {
                        currentPage: 1,
                        pageSize: 10,
                    };
                    this.getList();
                } else {
                    this.query.currentPage = 1;
                    this.$router.push({
                        path: "",
                        query: this.query,
                    });
                    this.getList();
                }
            },




            /*获取列表事件*/
            getList() {
                this.loading = true;
                this.list = [];
                getAddList(this.query)
                    .then((response) => {
                        if (response.code != 0) {
                            this.$message.error(response.message);
                            return false;
                        }
                        let datalist = response.data.list || [];
                        if (datalist.length > 0) {
                            let mylist = datalist;
                            for (var i = 0; i < mylist.length; i++) {
                                if (mylist[i].onshelfstatus != null) {
                                    mylist[i].onshelfstatus = mylist[i].onshelfstatus.toString();
                                }
                                if (mylist[i].recommendstatus != null) {
                                    mylist[i].recommendstatus = mylist[
                                        i
                                        ].recommendstatus.toString();
                                }
                            }
                            this.list = mylist;

                            console.info(this.list);
                        }
                        // this.list = response.data.list || [];

                        this.totalNumber = response.data.totalNumber || 0;
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                    });
            },

            //add一级
            topchange1() {
                for (var i = 0; i < this.category.length; i++) {
                    if (this.category[i].topcategoryid == this.formData.topcategoryid) {
                        this.busCommoditySecondaryCategoryList = this.category[
                            i
                            ].busCommoditySecondaryCategoryList;
                        this.categoryobj = this.category[i];
                        this.formData.topcategoryname = this.category[i].topcategoryname;
                        break;
                    }
                }
            },
            thirdchange1(type) {
                for (var i = 0; i < this.busCommodityThirdCategoryList.length; i++) {
                    if (
                        this.busCommodityThirdCategoryList[i].topcategoryid ==
                        this.formData.thirdcategoryid
                    ) {
                        this.ThirdCategoryobj = this.busCommodityThirdCategoryList[i];
                        if (this.ThirdCategoryobj.specification != null) {
                            let data = this.ThirdCategoryobj.specification.split(`","`);
                            let indata = [];
                            for (let i = 0; i < data.length; i++) {
                                let mydata = {
                                    key: "",
                                    val: "",
                                };
                                mydata.key = data[i];
                                mydata.val = "";
                                indata.push(mydata);
                            }
                            this.inputData = indata;
                        }
                        this.formData.thirdcategoryname = this.busCommodityThirdCategoryList[
                            i
                            ].thirdcategoryname;
                        this.classification = false;
                        break;
                    }
                }
                if (type == 2) {
                    this.getTemplate(this.formData.thirdcategoryid);
                }
            },
            getTemplate(thirdcategoryid) {
                var _this = this;
                // this.loading = true;
                this.categoryTemplate = [];
                const formData = new FormData();
                formData.append("threeCategoryId", thirdcategoryid);
                getGoodsCertificationInfo(formData)
                    .then((response) => {
                        if (response.code) {
                            this.$message.error(response.message);
                            this.loading = false;
                        }
                        if (response.data.templateFromList.length == 0) {
                            this.loading = false;
                            _this.categoryTemplate = [];
                            return false;
                        }
                        this.categoryTemplate = response.data.templateFromList[0];
                        console.info("-----------2" + JSON.stringify(this.categoryTemplate));
                        if(this.categoryTemplate.templateItemFormList!=null &&this.categoryTemplate.templateItemFormList!=undefined) {
                            this.categoryTemplate.templateItemFormList.forEach((item) => {
                                this.formData4[item.fieldname] = null;
                            });
                        }
                        // setTimeout(() => {
                        //     this.loading = false;
                        // }, 0.3 * 1000);
                    })
                    .catch((err) => {
                        this.$message.error(err);
                        this.loading = false;
                    });
            },
            //获得分类
            getAllCategory() {
                this.loading = true;
                getMainCategoryMap()
                    .then((response) => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        let data = response.data || [];
                        this.oneCategoryObj=response.data.one||{};
                        this.twoCategoryObj=response.data.two||{};
                        //this.busCommodityThirdCategoryList = data;
                        this.busCommodityThirdCategoryList = response.data.threeList || [];
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                        this.totalNumber = 0;
                    });
            },
            /*新增或者编辑提交事件*/
            formSumbit() {
                var ids = this.multipleSelection.map((item) => item.commodityid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning",
                    });
                    return;
                }

                this.$emit("on-select", ids, ids);
            },
            /*日期选择事件*/
            dateChange(val) {
                if (val == null) {
                    this.query.starttime = "";
                    this.query.endtime = "";
                } else {
                    this.query.starttime = val[0];
                    this.query.endtime = val[1];
                    this.query.currentPage = 1;
                }
                this.getList();
            },
            /*列表查询条件事件*/
            onSubmit() {
                this.query.currentPage = 1;
                this.$router.push({
                    path: "",
                    query: this.query,
                });
                this.getList();
            },

            /*刷新*/
            onRest() {
                this.$router.push({
                    path: "",
                });
                //刷新事件需要重置查询条件
                this.createTime = [];
                this.query = {
                    currentPage: 1,
                    pageSize: 10,
                };
                this.getList();
            },

            /*点击页数*/
            handleCurrentChange(val) {
                this.query.currentPage = val;
                this.getList();
            },

            /*选择每页条数【10,20,30,40,50】*/
            handleSizeChange(val) {
                this.query.pageSize = val;
                this.getList();
            },

            /*取消全选事件*/
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach((row) => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },

            /*列表复选框选择事件*/
            handleSelectionChange(val) {
                this.multipleSelection = val;
                if (val == "") {
                    this.cancelToggle = false;
                    return;
                }
                this.cancelToggle = true;
            },

            /*全选删除事件*/
            delGroup() {
                var ids = this.multipleSelection.map((item) => item.commodityid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning",
                    });
                    return;
                }
                this.handleDel(ids);
            },

            /*选中事件*/
            handleDel(ids) {
                if (ids) {
                    this.$confirm("确认要删除吗?", "提示", {
                        type: "warning",
                    })
                        .then(() => {
                            this.loading = true;
                            var params = new URLSearchParams();
                            params.append("ids", ids);
                            delBusCommodity(params)
                                .then((response) => {
                                    this.loading = false;
                                    if (response.code) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("删除成功");
                                    // 刷新数据
                                    //this.list.splice(index, 1);
                                    this.getList();
                                })
                                .catch(() => {
                                    this.loading = false;
                                });
                        })
                        .catch(() => {
                            this.$message.warning("已取消");
                        });
                }
            },
        },

        created() {
            console.log(this.$route.query.p, "$route1897");
            if (this.$route.query.p === "add") {
                this.isSkip = true;
            }
            this.getAllCategory();
            this.getList();

        },
    };
</script>
<style type="text/css">
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409eff;
    }

    .avatar-uploader-icon {
        font-size: 21px;
        color: #8c939d;
        width: 50px;
        height: 50px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
</style>
